package springboot.homework.util;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import springboot.homework.config.AppConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;


public class MyWebApplicationInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) {

            AnnotationConfigWebApplicationContext ac = new AnnotationConfigWebApplicationContext();

            ac.register(AppConfig.class);
            ac.setServletContext(servletContext);
            ac.refresh();

            DispatcherServlet servlet = new DispatcherServlet(ac);
            ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcher", servlet);
            registration.setLoadOnStartup(1);
            registration.addMapping("/");



    }
}

